package com.zifuchuan.stringtest;

public class Test07 {
    public static void main(String[] args) {
        addStringBuilder();
        addString();
    }
    //打印StringBuilder 操作50000次时间
    private static void addStringBuilder() {
        long start = System.currentTimeMillis();
        StringBuilder s=new StringBuilder();
        for (int i = 0; i <50000; i++) {
            //Stringbuilder 拼接方法
            s.append(i);
        }
        long end = System.currentTimeMillis();
        System.out.println("StringBuilder时间:"+(end-start));
    }
    //打印String 操作50000次时间
    public static void addString(){
        long start = System.currentTimeMillis();
        String s="";
        for (int i = 0; i <50000; i++) {
            //String 拼接方法
            s+=i;
        }
        long end = System.currentTimeMillis();
        System.out.println("String时间:"+(end-start));
    }
}
